var guanjia=({
	loginout : function(){
		$.ajax({
			type : "POST",
			dataType : 'json',
			url : "../login/ljLogout.do",
			data : {
			},
			success : function(data) {
				if(data.resultCode==0){
					storage.removeItem('flag');
					storage.removeItem('nickName');
					storage.removeItem('headimg');
					storage.removeItem('phone');
					$$.toast("退出成功");
					window.location.href = "../jsp/login.html";
				}
			}
		});
	},
	getCookie : function (name) 
	{ 
	    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	 
	    if(arr=document.cookie.match(reg))
	 
	        return unescape(arr[2]); 
	    else 
	        return null; 
	} ,
	getUserInfo : function  (){
		$.ajax({
			type : "POST",
			dataType : 'json',
			url : "../user/isLogin.do",
			data : {
				phone : guanjia.getCookie("phone")
			},
			success : function(data) {
				if(data.success){
					
					var flag="";
					if(data.user.flag==0) flag="租客";
					if(data.user.flag==1) flag="房东";
					if(data.user.flag==2) flag="管家";
					if (data.user.nickName!=null) 
					{$("#name").html("");
					$("#name").text(data.user.nickName+"("+flag+")");}
					if (data.user.headImg!=null)
					{$("#headimg").attr("src",data.user.headImg.split(",")[0]);}
					if(data.user!=null){
						$("#loginout").show();
						$("#auth").show();
					}
					if(data.user.openId !=undefined){
						$("#bindwx").text("已绑定微信");
					}
					if(data.user!=null && data.user.openId!=null){
						$("#auth").hide();
					}
					if(data.user.flag==0){
						$("#myfoot").show();
					}
				}
			}
		});
		},
		
		toLink : function (txt,tagrt) {
			$.ajax({
				type : "POST",
				dataType : 'json',
				url : "../user/isLogin.do",
				data : {
					phone : guanjia.getCookie("phone")
				},
				success : function(data) {
					if(data.success){
						document.location.href = "./" + txt;
					}else{
						 $$.alert(data.msg, function () {
					          window.location.href="./login.html?url="+encodeURIComponent(window.location.href);
					        });
					}
				}
			});
		},
		tologin : function (){
			window.location.href="../weixinImpl/login.do";
		},
});
$("#butler").click(function(){
	   window.location.href="./login.html?url="+encodeURIComponent(window.location.href);
})

